function itpshow() {
	$(".u_tipWindow,.u_tipBackground").show();
};
function itphide() {
	$(".u_tipWindow,.u_tipBackground,.my_rofile").hide();
};
function change_show(){
	$(".payment_xx .itp_form").show();
	$(".payment_xx .bankinfo").hide();
};
//处理加载错误图跟src路径为空替换一张默认图
$.DashenImgDelay = function(objImg,srcImg){
	$(objImg).each(function(){
		$(this).error(function() {
			$(this).attr("src", ""+srcImg+"");
			$(this).css({"background-color":"transparent"});
		});
		if($(this).attr("src")==0){
			$(this).attr("src", ""+srcImg+"");
			$(this).css({"background-color":"transparent"});
		}
	})
}
/*hover*/
$.Dashenhover =function(obj) {
	$(obj).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
};
/*click*/
$.Dashenclick =function(obj) {
	$(obj).click(function(){$(this).toggleClass("hover");});
};

/*tab选项卡*/
$.Dashentab = function(tabBar,tspan,tabCon,citem,class_name,tabEvent,i){
  	var $tab_menu=$(tabBar).find(tspan);
	// 初始化操作
	$(tabBar).find(tspan).eq(i).addClass(class_name);
	$(tabCon).find(citem).eq(i).show();
	
	$tab_menu.on(tabEvent,function(){
		$(this).addClass(class_name).siblings().removeClass(class_name);
		var index=$tab_menu.index(this);
		$(tabCon).find(citem).eq(index).show().siblings().hide();
	});
};
/*左右切换图片滚动效果*/
$.Dashensilder = function(sil_li,sil_ul,l_btn,r_btn,numlength,num){
	$(sil_ul).css("width", $(sil_li).length*numlength);

	var lc1 = 0;
	var rc1 = $(sil_li).length-num;
	
	$(l_btn).click(function(){
		if (lc1 < 1) {
			alert("已经是第一个视频");
			return;
		}
		lc1--;
		rc1++;
		$(sil_ul).animate({left:"+=" + numlength + 'px'}, 1000);
	});

	$(r_btn).click(function(){
		if (rc1 < 1){
			alert("已经是最后一个视频");
			return;
		}
		lc1++;
		rc1--;
		$(sil_ul).animate({left:'-=' + numlength + 'px'}, 1000);
	});	
}

/*幻灯片*/
//预加载jquery.lazyload.js封装
;(function($) {
    	$.fn.easySlider = function(a) {
		return this.each(function() {
			var s = $(this),
				B = s.find("ul#show_pic li"),
				w = 0,
				y = 1000,
				r = 1000,
				t = 10,
				z = false,
				C = 3000,
				u, i = "",
				D, A, x = B.length;
			B.css({
				opacity: 0,
				zIndex: t - 1
			}).eq(w).css({
				opacity: 1,
				zIndex: t
			});
			for (A = 0; A < x; A++) {
				i += '<a>' + (A + 1) + "</a>"
			}
			D = s.append($('<div class="img_pagebox"><div id="icon_num" class="pageBox">' + i + "</div>").css("zIndex", t + 1)).find(".pageBox a");
			D.mouseenter(function() {
				w = $(this).text() * 1 - 1;
				B.eq(w).stop().fadeTo(r, 1, function() {
					if (!z) {
						u = setTimeout(v, C + r)
					}
				}).css("zIndex", t).siblings("li").stop().fadeTo(y, 0).css("zIndex", t - 1);
				$(this).addClass("active").siblings().removeClass("active");
				return false
			}).focus(function() {
				$(this).blur()
			}).eq(w).addClass("active");
			s.hover(function() {
				z = true;
				clearTimeout(u)
			}, function() {
				z = false;
				u = setTimeout(v, C)
			});
			function v() {
				if (z) {
					return
				}
				w = (w + 1) % D.length;
				D.eq(w).mouseenter()
			}
			u = setTimeout(v, C)
		})
	};
	$.fn.scrollLoading = function(options) {
		var defaults = {
			attr: "style-url",
			container: $(window),
			callback: $.noop
		};
		var params = $.extend({}, defaults, options || {});
		params.cache = [];
		$(this).each(function() {
			var node = this.nodeName.toLowerCase(), url = $(this).attr(params["attr"]);
			//重组
			var data = {
				obj: $(this),
				tag: node,
				url: url
			};
			params.cache.push(data);
		});
		
		var callback = function(call) {
			if ($.isFunction(params.callback)) {
				params.callback.call(call.get(0));
			}
		};
		//动态显示数据
		var loading = function() {
			
			var contHeight = params.container.height();
			if ($(window).get(0) === window) {
				contop = $(window).scrollTop();
			} else {
				contop = params.container.offset().top;
			}		
			
			$.each(params.cache, function(i, data) {
				var o = data.obj, tag = data.tag, url = data.url, post, posb;

				if (o) {
					post = o.offset().top - contop, post + o.height();
	
					if ((post >= 0 && post < contHeight) || (posb > 0 && posb <= contHeight)) {
						if (url) {
							//在浏览器窗口内
							if (tag === "span") {
								//图片，改变src
								callback(o.attr("style", url));		
							}
							else if (tag === "img") {
								callback(o.attr("src", url));	
							} 
							else {
								o.load(url, {}, function() {
									callback(o);
								});
							}
						} else {
							// 无地址，直接触发回调
							callback(o);
						}
						data.obj = null;	
					}
				}
			});	
		};
		
		//事件触发
		//加载完毕即执行
		//loading();
		//滚动执行
		//params.container.bind("scroll", loading);
	};
})(jQuery);
$(function () {
	$(".search input").focus(function(){
		$(this).parent().animate({"width":"160px"});
	}).blur(function(){
		$(this).parent().animate({"width":"140px"});
	});
	function showScroll(){var scrollValue=$(window).scrollTop();
		var _html = '<div class="scroll_html" id="u_scroll" style="display:none;"><a href="javascript:void(0);" class="scroll_html_a nav-backtop"><em>顶部</em></a></div>';
		$('body > .wrap').append(_html);
		$(window).scroll( function() {
			var scrollValue=$(window).scrollTop();
			scrollValue > 100 ? $('div[class=scroll_html]').fadeIn():$('div[class=scroll_html]').fadeOut();
		} );
		$('#u_scroll').click(function(){
			$("html,body").animate({scrollTop:0},200);
		});
	};
	showScroll();
	$("img").delayLoading({
		defaultImg: "/application/web/views/images/alpha.png",           // 预加载前显示的图片
		errorImg: "",                        // 读取图片错误时替换图片(默认：与defaultImg一样)
		imgSrcAttr: "style-url",           // 记录图片路径的属性(默认：originalSrc，页面img的src属性也要替换为originalSrc)
		beforehand: 0,                       // 预先提前多少像素加载图片(默认：0)
		event: "scroll",                     // 触发加载图片事件(默认：scroll)
		duration: "normal",                  // 三种预定淡出(入)速度之一的字符串("slow", "normal", or "fast")或表示动画时长的毫秒数值(如：1000),默认:"normal"
		container: window,                   // 对象加载的位置容器(默认：window)
		success: function (imgObj) { },      // 加载图片成功后的回调函数(默认：不执行任何操作)
		error: function (imgObj) { }         // 加载图片失败后的回调函数(默认：不执行任何操作)
	});
    $(".userinfo > h2").hover();
	$(".p_column > dl").find("dt").click(function(){
		//$(this).parent("dl").addClass("hover").siblings().removeClass("hover");
		$(this).parent("dl").toggleClass("hover");
	});
    $("#show_pic li").removeClass("hide");
	$("#picBox").easySlider()

	//顶部搜索
	$("#search_word").keypress(function(event) {
		if (event.which == 13) {
			var search_word = $.trim($("#search_word").val());
			var type = $("#search_word").data('type');
			if (search_word != '') {
				window.location.href="/search/index/"+search_word+"/"+type
			}
		}
	});
	$(".ds_search").click(function(){
		var search_word = $.trim($("#search_word").val());
		var type = $("#search_word").data('type');
		if(search_word === ""){
			alert("搜索关键词还没有填写","$('#search_word').focus();");
			return false
		}
		search_word = encodeURIComponent(search_word).replace(new RegExp("'","g"),"");
		window.location.href="/search/index/"+search_word+"/"+type;
	});
    // 选项卡切换
	$.Dashenhover(".userinfo li.tab");
    // 退出登录
	$("a#logout").on("click", function(){
    	$.ajax({
    		  type: "POST",
    		  url: "/user/logout.html",
    		  async:false,
    		  data: {},
    		  dataType: "json",
    		  success: function(data){
    			if(data.result_code ==1 ){
    				if(data.result_data.go_url.indexOf('live/index') ) {
    					location.reload();
    				}
    						
    				$('iframe').each(function(index){
    					var url=$(this).attr("src");
    					var url_arr=url.split("?");
    					url=url_arr[0];
    					$(this).attr("src",url+"?randomNum="+randomNum(10));
    				});
    				$(".login-out").hide();
    				$(".login").show();	
    				$(".anchor_info").remove();
    				$("#head_image_url").attr('src',"");	
    				$("#head_image_url").attr('alt',"");	
    				$("#nick").html("");	
    			}  
    		}
    	});
	});
	//textarea输入框限制字数
	$("#weibo").keyup(function(){
		var len=$("#weibo").val().length;	
		if(len>300){
			$("#ceiling").show();
			var num=$("#weibo").val().substring(0,300);
			$("#weibo").val(num);
			return false;
		}
		else{
			$("#ceiling").hide();
			$("#word").text($("#weibo").val().length);
			return false;
		}
	})
	/*点击上传图片*/
	$("input[type='file']").change(function(evt){
		var _this = $(this);
		var files = evt.target.files; 

		for (var i = 0, f; f = files[i]; i++) {

		  if (!f.type.match('image.*')) {
			continue;
		  }
		
		  var reader = new FileReader();
		  reader.onload = (function(theFile) {
			return function(e) {
				_this.siblings().show();  
				//$(".ut_btn span").css({"background-image":"url("+e.target.result+")"});                       
				$(".ut_photo img").attr("src",e.target.result);  //预览图片的位置 
				_this.siblings().find("img").attr("src",e.target.result);              
			};
		  })(f);

		  reader.readAsDataURL(f);
		}
	});
	//封面图片
	$(".cover_photo").hover(function(){
		$(this).toggleClass("hover");
	})
	
	//处理小于1400屏幕-录播页面两个左右滚动效果
	var sw = $("body").width();
	if(sw <= 1400){
		$.Dashensilder("#silder_01 .wk_silder .video-list li","#silder_01 .wk_silder .video-list","#silder_01 .wk_silder .s_pre","#silder_01 .wk_silder .s_next","180",4);
		$.Dashensilder("#silder_02 .wk_silder .video-list li","#silder_02 .wk_silder .video-list","#silder_02 .wk_silder .s_pre","#silder_02 .wk_silder .s_next","180",4);
	}else{
		$.Dashensilder("#silder_01 .wk_silder .video-list li","#silder_01 .wk_silder .video-list","#silder_01 .wk_silder .s_pre","#silder_01 .wk_silder .s_next","223",4);
		$.Dashensilder("#silder_02 .wk_silder .video-list li","#silder_02 .wk_silder .video-list","#silder_02 .wk_silder .s_pre","#silder_02 .wk_silder .s_next","223",4);	
	}
	
	//处理加载错误图跟src路径为空替换一张默认图
	$.DashenImgDelay(".avatar img,.img_error","/application/web/views/user_center/skin/images/default_user.png");
	$.DashenImgDelay(".video-list-item .pic img","/application/web/views/images/alpha.png");
});